<template>
    <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from "echarts";
// import { dayMoney } from "../../../api/public";
require("echarts/theme/macarons");
export default {
    props: {
        className: {
            type: String,
            default: "chart",
        },
        width: {
            type: String,
            default: "100%",
        },
        height: {
            type: String,
            default: "350px",
        },
        autoResize: {
            type: Boolean,
            default: true,
        },
    },
    data() {
        return {
            chart: null,
        };
    },
    mounted() {
        // dayMoney().then((res) => {
        //     var time = res.data.datalist.reverse();
        //     var yes=res.data.list.reverse();
        //     var no=res.data.no.reverse();
        //     this.$nextTick(() => {
        //         this.initChart(time,yes,no);
        //     });
        // });
    },
    beforeDestroy() {
        if (!this.chart) {
            return;
        }
        this.chart.dispose();
        this.chart = null;
    },
    methods: {
        initChart(time,yes,no) {
            this.chart = echarts.init(this.$el, "macarons");

            this.setOptions(time,yes,no);
        },
        setOptions(time,yes,no) {
            this.chart.setOption({
                xAxis: {
                    data: time,
                    boundaryGap: false,
                    axisTick: {
                        show: false,
                    },
                },
                grid: {
                    left: 10,
                    right: 10,
                    bottom: 20,
                    top: 30,
                    containLabel: true,
                },
                tooltip: {
                    trigger: "axis",
                    axisPointer: {
                        type: "cross",
                    },
                    padding: [5, 10],
                },
                yAxis: {
                    axisTick: {
                        show: false,
                    },
                },
                legend: {
                    data: ["支出工资", "充值"],
                },
                series: [
                    {
                        name: "支出工资",
                        itemStyle: {
                            normal: {
                                color: "#FF005A",
                                lineStyle: {
                                    color: "#FF005A",
                                    width: 2,
                                },
                            },
                        },
                        smooth: true,
                        type: "line",
                        data: no,
                        animationDuration: 2800,
                        animationEasing: "cubicInOut",
                    },
                    {
                        name: "充值",
                        smooth: true,
                        type: "line",
                        itemStyle: {
                            normal: {
                                color: "#3888fa",
                                lineStyle: {
                                    color: "#3888fa",
                                    width: 2,
                                },
                                areaStyle: {
                                    color: "#f3f8ff",
                                },
                            },
                        },
                        data: yes,
                        animationDuration: 2800,
                        animationEasing: "quadraticOut",
                    },
                ],
            });
        },
    },
};
</script>
